clear all
set more off

global chemin "HERE indicated path to the main folder"
cd "$chemin\data"

use final_IHME22, clear
drop if recipient_name == "Unallocated/Unspecified"
* we drop 2019 and 2020 because we don't have bilateral data but just global data
drop if year >= 2019
gen MCP = 0
replace MCP = 1 if year <1993 /* actif jusqu'en 12/1992 inclus */
replace MCP = 1 if year == 1995
replace MCP = 1 if year >1999 & year <2009 /* actif en 1999/2000 et à partir du 01/2001 jusqu'en 12/2008*/
replace MCP = 1 if year >2016 /*actif 01/2017 - 12/2020*/ 


* Intsrument construction
	* Part 1 : probability of receiving FP aid when MCP is not active
	gen aid_pc = (rmh_fp_dah_20_US >0)
	bys recipient_name : egen aid = mean(aid_pc) if MCP == 0
	bys recipient_name : egen FPr = mean(aid)

* instrument 1 : Probability of receiving FP aid when MCP is not active * share channelled through NGO during OBAMA term * policy
	gen instrument1 = FPr * share_NGOUS_Obama * MCP
* instrument 2 : Probability of receiving FP aid when MCP is not active * share channelled through NGO when MCP not active * policy
	gen instrument2 = FPr * share_NGOUS_MCP * MCP

* Creation of controls
	gen lngdppc = ln(GDPpc_r)
	gen lnpopr = ln(pop_r)
	gen laidfp = ln(rmh_fp_dah_20 + ((rmh_fp_dah_20^2 +1)^0.5))
	gen laidUS = ln(rmh_fp_dah_20_US + ((rmh_fp_dah_20_US^2 +1)^0.5))

	gen laidfp2 = ln(rmh_fp_dah_20 + 1)
	gen laidUS2 = ln(rmh_fp_dah_20_US + 1)

	egen id_o = group(donor)
	egen id_dr = group(donor recipient_name)
	egen id_r = group( recipient_name)
	gen fert2 = fertility_r *fertility_r

xtset id_dr year
global controls  lngdppc lnpopr poverty_r
global controls1 lngdppc lnpopr poverty_r life_expectencyfe_r incidenceHIV_r HIV1549_r fert2 fertility_r adofertility_r maternalmortality_r
global controls2 lngdppc lnpopr poverty_r life_expectencyfe_r incidenceHIV_r HIV1549_r fert2 fertility_r adofertility_r maternalmortality_r polity2
global controls3 lngdppc lnpopr poverty_r life_expectencyfe_r incidenceHIV_r HIV1549_r fert2 fertility_r adofertility_r maternalmortality_r polity2 UN_dr 

* controls interacted with FPr*ShareNGOr
foreach i of varlist $controls3 {
	gen `i'_int = `i' * FPr * share_NGOUS_Obama
}


* Défeinition of different set of controls 
global controlsi  L.lngdppc* L.lnpopr* L.poverty_r*    																				
global controls1i L.lngdppc* L.lnpopr* L.poverty_r* L.life_expectencyfe_r* L.HIV1549_r* L.incidenceHIV_r* L.fert2* L.fertility* L.adofertility* L.maternalmortality_r*
global controls2i L.lngdppc* L.lnpopr* L.poverty_r* L.life_expectencyfe_r* L.HIV1549_r* L.incidenceHIV_r* L.fert2* L.fertility* L.adofertility* L.maternalmortality_r* L.polity2* 
* will exclude the EU and the BMGF because no data on UN vote...
global controls3i L.lngdppc* L.lnpopr* L.poverty_r* L.life_expectencyfe_r* L.HIV1549_r* L.incidenceHIV_r* L.fert2* L.fertility* L.adofertility* L.maternalmortality_r* L.polity2* L.UN_dr* 


label variable laidUS "Log of US FP aid\$_{rt-1}$"
label variable instrument1 "MCP\$_{t}$ * FP\$_{r}$ * shareONG\$_{r}$"
gen laidrm = ln(rmh_dah_20 + ((rmh_dah_20^2 +1)^0.5))
gen laidrmUS = ln(rmh_dah_20_US + ((rmh_dah_20_US^2 +1)^0.5))
gen laidfp_bound = ln(rmh_fp_dah_20_boundmax + ((rmh_fp_dah_20_boundmax^2 +1)^0.5))
gen laidUS_bound = ln(rmh_fp_dah_20_boundmax_US + ((rmh_fp_dah_20_boundmax_US^2 +1)^0.5))

/* Baseline results*/
ivreghdfe laidfp $controls2i (laidUS =instrument1 ),  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor) first
gen in_sample4 =e(sample)


ivreghdfe laidfp $controls2i (L.laidUS =L.instrument1 ),  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor) first
est store Baseline1
		estadd local DRFE "Yes": Baseline1
		estadd local DYFE "Yes": Baseline1
		estadd local Cont "Yes": Baseline1
		
ivreghdfe laidfp $controls2i (L2.laidUS =L2.instrument1 ),  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor) first
est store Baseline2
		estadd local DRFE "Yes": Baseline2
		estadd local DYFE "Yes": Baseline2
		estadd local Cont "Yes": Baseline2





* Placebo timing
	preserve
	keep if year >2000 & year <2009
	drop MCP instrument1
	gen MCP = (year <2005)
	tab year MCP
* instrument 1 : Probability of receiving FP aid when MCP is not active * share channelled through NGO during OBAMA term * policy
	gen instrument1 = FPr * share_NGOUS_Obama * MCP
	ivreghdfe laidfp $controls2i (L2.laidUS=L2.instrument1),  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor )  first savefirst savefprefix(stP32)
	est store P32
	estadd local DRFE "Yes": P32
	estadd local DYFE "Yes": P32
	estadd local Cont "Yes": P32
	ivreghdfe laidfp $controls2i (L.laidUS=L.instrument1),  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor )  first savefirst savefprefix(stP31)
	est store P31
	estadd local DRFE "Yes": P31
	estadd local DYFE "Yes": P31
	estadd local Cont "Yes": P31
	restore

	preserve
	drop MCP instrument1
	keep if year >2008 & year <2017
	gen MCP = (year >2012)
	tab year MCP
	* instrument 1 : Probability of receiving FP aid when MCP is not active * share channelled through NGO during OBAMA term * policy
	gen instrument1 = FPr * share_NGOUS_Obama * MCP
	ivreghdfe laidfp $controls2i (L2.laidUS=L2.instrument1),  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor )  first savefirst savefprefix(stP42)
	est store P42
	estadd local DRFE "Yes": P42
	estadd local DYFE "Yes": P42
	estadd local Cont "Yes": P42
	ivreghdfe laidfp $controls2i (L.laidUS=L.instrument1),  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor )  first savefirst savefprefix(stP41)
	est store P41
	estadd local DRFE "Yes": P41
	estadd local DYFE "Yes": P41
	estadd local Cont "Yes": P41
	restore

		ivreghdfe laidfp $controls2i (F.laidUS =F.instrument1 ),  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor) first savefirst savefprefix(stForward)
		est store Forward
		estadd local DRFE "Yes": Forward
		estadd local DYFE "Yes": Forward
		estadd local Cont "Yes": Forward

	esttab P31 P32 P41 P42 Forward using "..\output\placebo.tex" ,  replace ///
		drop(* )  ///
		b(a3) se(a3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
		substitute($ \$ ) /// /* Formatting label */
		nonumber  nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  /// /* some options on formatings */
		mgroups("Bush Administration" "Obama Admisnistration" "Future US aid", pattern(1 0 1 0 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles 
	esttab  P31 P32 P41 P42 Forward /*OLS*/ using "..\output\placebo.tex" ,  append ///
		keep(L.laidUS L2.laidUS F.laidUS  )  ///
		b(a3) se(a3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
		  substitute($ \$ ) /// /* Formatting label */
		coeflabel(L.laidUS "USFPaid\$_{rt-1}$" ///
		L2.laidUS "USFPaid\$_{rt-2}$"  ///
		F.laidUS "USFPaid\$_{rt+1}$") ///
		nonumber compress nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  /// /* some options on formatings */
		mgroups("2SLS Estimates - Dep. Var.: FPA\$_{drt}$" , pattern(1 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles
	esttab st* using "..\output\placebo.tex" ,  append ///
		drop(* )  ///
		b(a3) se(a3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
		substitute($ \$ ) /// /* Formatting label */
		nonumber  nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  /// /* some options on formatings */
		mgroups("First-Stage Estimates - Dep. Var.: FPA\$_{drt-k}$" , pattern(1 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles
	esttab  st*  /*OLS*/ using "..\output\placebo.tex" ,  append ///
		keep(L.instrument1 L2.instrument1 F.instrument1)  ///
		b(a3) se(a3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
		  substitute($ \$ ) /// /* Formatting label */
		coeflabel(L.instrument1 "FP\$_{r}$ * shareNGO\$_{r}$ * Placebo\$_{t-1}$" ///
		L2.instrument1 "FP\$_{r}$ * shareNGO\$_{r}$ * Placebo\$_{t-2}$"  ///
		F.instrument1 "FP\$_{r}$ * shareNGO\$_{r}$ * MCP\$_{t+1}$" ) ///
		nonumber compress nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  nomtitles
	esttab P31 P32 P41 P42 Forward using "..\output\placebo.tex" ,  append ///
		drop(* )  ///
		b(a3) se(a3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
		substitute($ \$ ) /// /* Formatting label */
		nonumber  nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se nomtitles /// /* some options on formatings */
		scalars("N Obs." "df_a_nested Donor-recipient pair" "N_clust1 Recipient" "widstat K-P. F-Stat" ///
		"DRFE Donor-Recipient FE" ///
		"DYFE Donor-Year FE" ///
		"Cont Controls\$ _{rt-1}$")  sfmt(a3) 

		
		****************************** Robustness ******************************
**# Bookmark #1
* round
	* US bound
	preserve
		ivreghdfe laidfp $controls2i (L2.laidUS_bound=L2.instrument1) if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first 
		est store R12
		estadd local DRFE "Yes": R12
		estadd local DYFE "Yes": R12
		estadd local Cont "Yes": R12
		ivreghdfe laidfp $controls2i (L.laidUS_bound=L.instrument1) if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first 
		est store R11
		estadd local DRFE "Yes": R11
		estadd local DYFE "Yes": R11
		estadd local Cont "Yes": R11
	restore
	* donor and US bound
	preserve
		ivreghdfe laidfp_bound $controls2i (L2.laidUS_bound=L2.instrument1) if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first 
		est store R22
		estadd local DRFE "Yes": R22
		estadd local DYFE "Yes": R22
		estadd local Cont "Yes": R22
		ivreghdfe laidfp_bound $controls2i (L.laidUS_bound=L.instrument1) if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first 
		est store R21
		estadd local DRFE "Yes": R21
		estadd local DYFE "Yes": R21
		estadd local Cont "Yes": R21
	restore
	* reproductice and maternal aid 
		ivreghdfe laidfp $controls2i (L2.laidrmUS=L2.instrument1) if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first 
		est store R32
		estadd local DRFE "Yes": R32
		estadd local DYFE "Yes": R32
		estadd local Cont "Yes": R32
		ivreghdfe laidfp $controls2i (L.laidrmUS=L.instrument1) if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first 
		est store R31
		estadd local DRFE "Yes": R31
		estadd local DYFE "Yes": R31
		estadd local Cont "Yes": R31
		
				
		ivreghdfe laidfp $controls2i (L2.laidUS=L2.instrument1) if in_s == 1 &  year >=2004,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first 
		est store R42
		estadd local DRFE "Yes": R42
		estadd local DYFE "Yes": R42
		estadd local Cont "Yes": R42
		ivreghdfe laidfp $controls2i (L.laidUS=L.instrument1) if in_s == 1 & year >=2004,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first 
		est store R41
		estadd local DRFE "Yes": R41
		estadd local DYFE "Yes": R41
		estadd local Cont "Yes": R41
	
	* excluding PEPFAR countries
		preserve 
		drop if recipient_name == "Botswana"
		drop if recipient_name == "Cote d'Ivoire"
		drop if recipient_name == "Ethiopia"
		drop if recipient_name == "Guyana"
		drop if recipient_name == "Haiti"
		drop if recipient_name == "Kenya"
		drop if recipient_name == "Mozambique"
		drop if recipient_name == "Namibia"
		drop if recipient_name == "Nigeria"
		drop if recipient_name == "Uganda"
		drop if recipient_name == "South Africa"
		drop if recipient_name == "Rwanda"
		drop if recipient_name == "Tanzania"
		drop if recipient_name == "Vietnam"
		drop if recipient_name == "Zambia"
		ivreghdfe laidfp $controls2i (L2.laidUS=L2.instrument1) if in_s == 1,  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor ) 
		est store R82
		estadd local DRFE "Yes": R82
		estadd local DYFE "Yes": R82
		estadd local Cont "Yes": R82
		ivreghdfe laidfp $controls2i (L.laidUS=L.instrument1) if in_s == 1,  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor ) 
		est store R81
		estadd local DRFE "Yes": R81
		estadd local DYFE "Yes": R81
		estadd local Cont "Yes": R81
		restore
		
		preserve
		ivreghdfe laidfp $controls2i (L2.laidUS=L2.instrument1) if in_s == 1,  absorb(id_dr i.year##i.id_o i.year##i.wb_location_id )  cluster(recipient_name donor ) first 
		est store R92
		estadd local DRFE "Yes": R92
		estadd local DYFE "Yes": R92
		estadd local Cont "Yes": R92
		ivreghdfe laidfp $controls2i (L.laidUS=L.instrument1) if in_s == 1,  absorb(id_dr i.year##i.id_o i.year##i.wb_location_id )  cluster(recipient_name donor ) first 
		est store R91
		estadd local DRFE "Yes": R91
		estadd local DYFE "Yes": R91
		estadd local Cont "Yes": R91
	restore
	
**# Bookmark #2
	* using CRS data
		preserve
		use final_CRS22, clear
		drop if donor == "UNFPA"
		drop if donor == "UNICEF"
		drop if donor == "United States"
		drop if donor == "Czech Republic"
		drop if donor == "Iceland"
		drop if donor == "Slovak Republic"
		drop if year >= 2019
		drop if year <2004
		gen MCP = 0
		replace MCP = 1 if year <1993 /* actif jusqu'en 12/1992 inclus */
		replace MCP = 1 if year == 1995
		replace MCP = 1 if year >1999 & year <2009 /* actif en 1999/2000 et à partir du 01/2001 jusqu'en 12/2008*/
		replace MCP = 1 if year >2016 /*actif 01/2017 - 12/2020*/ 

		* Intsrument construction
			* Part 1 : probability of receiving FP aid when MCP is not active
			gen aid_pc = (usd_disbursement_defl_US >0)
			bys recipient_name : egen aid = mean(aid_pc) if MCP == 0
			bys recipient_name : egen FPr = mean(aid)
			* Part 1 : probability of receiving commitment FP aid when MCP is not active
			gen aid_pc2 = (usd_commitment_defl_US >0)
			bys recipient_name : egen aid2 = mean(aid_pc2) if MCP == 0
			bys recipient_name : egen FPr2 = mean(aid2)

		* instrument 1 : Probability of receiving FP aid when MCP is not active * share channelled through NGO during OBAMA term * policy
			gen instrument1 = FPr * share_NGO_US * MCP
			gen instrument2 = FPr2 * share_NGO_US * MCP


			gen lngdppc = ln(GDPpc_r)
			gen lnpopr = ln(pop_r)
			gen laidfp = ln(usd_disbursement_defl + ((usd_disbursement_defl^2 +1)^0.5))
			gen laidUS = ln(usd_disbursement_defl_US + ((usd_disbursement_defl_US^2 +1)^0.5))
			gen laid130 = ln(usd_disbursement_defl_130 + ((usd_disbursement_defl_130^2 +1)^0.5))
			gen laidfpc = ln(usd_commitment_defl + ((usd_commitment_defl^2 +1)^0.5))
			gen laidUSc = ln(usd_commitment_defl_US + ((usd_commitment_defl_US^2 +1)^0.5))


			egen id_o = group(donor)
			egen id_dr = group(donor recipient_name)


			gen fert2 = fertility_r *fertility_r

			xtset id_dr year
			global controls2 lngdppc lnpopr poverty_r life_expectencyfe_r incidenceHIV_r HIV1549_r fert2 fertility_r adofertility_r maternalmortality_r polity2
			global controls3 lngdppc lnpopr poverty_r life_expectencyfe_r incidenceHIV_r HIV1549_r fert2 fertility_r adofertility_r maternalmortality_r polity2 UN_dr 

			foreach i of varlist $controls2 {
			gen `i'_int = `i' *   FPr * share_NGO_US
			}
			global controls2i L.lngdppc* L.lnpopr* L.poverty_r* L.life_expectencyfe_r* L.HIV1549_r* L.incidenceHIV_r* L.fert2* L.fertility* L.adofertility* L.maternalmortality_r* L.polity2* 
			global controls3i L.lngdppc* L.lnpopr* L.poverty_r* L.life_expectencyfe_r* L.HIV1549_r* L.incidenceHIV_r* L.fert2* L.fertility* L.adofertility* L.maternalmortality_r* L.polity2* L.UN_dr* 

		ivreghdfe laidfp $controls2i (L2.laidUS=L2.instrument1),  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor ) first
		gen in_sample4 =e(sample)


		* "baseline"
		ivreghdfe laidfp $controls2i (L2.laidUS=L2.instrument1) if in_s == 1,  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor ) 
		est store R52
		estadd local DRFE "Yes": R52
		estadd local DYFE "Yes": R52
		estadd local Cont "Yes": R52
		ivreghdfe laidfp $controls2i (L.laidUS=L.instrument1) if in_s == 1,  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor ) 
		est store R51
		estadd local DRFE "Yes": R51
		estadd local DYFE "Yes": R51
		estadd local Cont "Yes": R51
		
		* reproductive and maternal health
		
		
		ivreghdfe laid130 $controls2i (L2.laidUS=L2.instrument1) if in_s == 1,  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor ) 
		est store R62
		estadd local DRFE "Yes": R62
		estadd local DYFE "Yes": R62
		estadd local Cont "Yes": R62
		ivreghdfe laid130 $controls2i (L.laidUS=L.instrument1) if in_s == 1,  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor ) 
		est store R61
		estadd local DRFE "Yes": R61
		estadd local DYFE "Yes": R61
		estadd local Cont "Yes": R61
		* commitment
		drop  laidfp
		rename laidfpc laidfp
		ivreghdfe laidfp $controls2i (L2.laidUSc=L2.instrument1) if in_s == 1,  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor ) 
		est store R72
		estadd local DRFE "Yes": R72
		estadd local DYFE "Yes": R72
		estadd local Cont "Yes": R72
		ivreghdfe laidfp $controls2i (L.laidUSc=L.instrument1) if in_s == 1,  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor ) 
		est store R71
		estadd local DRFE "Yes": R71
		estadd local DYFE "Yes": R71
		estadd local Cont "Yes": R71
		restore
		
	
	esttab Baseline1 R11 R21 R81 R31 R51 R61 R71 R91 /*OLS*/ using "..\output\robust.tex" ,  replace ///
		drop(* )  ///
		b(a2) se(a2) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
		substitute($ \$ ) /// /* Formatting label */
		nonumber  nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  /// /* some options on formatings */
		mgroups("IHME data" "CRS-OECD data", pattern(1 0 0 0 0 0 1 0 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles
	esttab  Baseline1 R81 R11 R21 R31 R91 R51 R61 R71  /*OLS*/ using "..\output\robust.tex" ,  append ///
		keep(L.laidUS L.laidUS_bound L.laidrmUS L.laidUSc)  ///
		b(3) se(3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
		  substitute($ \$ ) /// /* Formatting label */
		coeflabel(L.laidUS "USFPaid\$_{rt-1}$" ///
		L.laidUS_bound "RUSFPaid\$_{rt-1}$" ///
		L.laidrmUS  "USRMHaid\$_{rt-1}$" ///
		L.laidUSc "USFPcom\$_{rt-1}$"  ) ///
		nonumber compress nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  /// /* some options on formatings */
		mgroups("Baseline" "PEPFAR"  "FP\$_{drt}$" "Round" "RMH" "RYFE" "FP" "RMH" "Commit.", pattern(1 1 1 1 1 1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles 
	esttab  Baseline2 R82 R12 R22 R32 R92 R52 R62 R72 /*OLS*/ using "..\output\robust.tex" ,  append ///
		keep(L2.laidUS L2.laidUS_bound L2.laidrmUS L2.laidUSc)  ///
		b(3) se(3)  starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
		  substitute($ \$ ) /// /* Formatting label */
		coeflabel(	L2.laidUS "USFPaid\$_{rt-2}$"  ///
		L2.laidUS_bound "RUSFPaid\$_{rt-2}$"  ///
		L2.laidrmUS  "USRMHaid\$_{rt-2}$" ///
		L2.laidUSc "USFPcom\$_{rt-2}$"  ) ///
		nonumber compress nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  nomtitles ///
		scalars("N Obs." "widstat K-P. F-Stat" ///
		"DRFE D-R FE" ///
		"DYFE D-Y FE" ///
		"Cont Controls\$ _{rt-1}$")  sfmt(a3) 
	
		
	
		
 
**# Bookmark #4
	* excluding one pair
keep if in_s == 1 | year == 1990
preserve
qui ivreghdfe laidfp $controls2i (L2.laidUS=L2.instrument1) if in_s == 1 ,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first 
drop *
set obs 1
gen sde = .
gen tstat = .
gen donor = .
gen recipient = .
gen N = e(N)
save resultat2, replace
restore
levelsof id_o if in_s==1, local(levelo) clean
levelsof id_r if in_s==1, local(levelr) clean
	foreach i of local levelo {
		foreach j of local levelr {
preserve
di "donor `i' recipient `j'"
qui ivreghdfe laidfp $controls2i (L2.laidUS=L2.instrument1) if id_o != `i' & id_r != `j',  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) 
mat V =e(V)
drop *
set obs 1
gen donor = `i'
gen recipient = `j'
gen sde = V[1,1]
gen estimate = _b[L2.laidUS] 
gen tstat = estimate / sqrt(sde)
gen N = e(N)
append using resultat2
save resultat2, replace
restore
}
}

preserve
qui ivreghdfe laidfp $controls2i (L.laidUS=L.instrument1) if in_s == 1 ,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first 
drop *
set obs 1
gen sde = .
gen tstat = .
gen donor = .
gen recipient = .
gen N = e(N)
save resultat1, replace
restore
levelsof id_o if in_s==1, local(levelo) clean
levelsof id_r if in_s==1, local(levelr) clean
	foreach i of local levelo {
		foreach j of local levelr {
preserve
di "donor `i' recipient `j'"
qui ivreghdfe laidfp $controls2i (L.laidUS=L.instrument1) if id_o != `i' & id_r != `j',  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) 
mat V =e(V)
drop *
set obs 1
gen donor = `i'
gen recipient = `j'
gen sde = V[1,1]
gen estimate = _b[L.laidUS] 
gen tstat = estimate / sqrt(sde)
gen N = e(N)
append using resultat1
save resultat1, replace
restore
}
}

use resultat2, clear
sum estimate, det
tab donor  if estimate <r(p1)
hist estimate ,   addplot(pci 0 0.0858576 150  0.0858576)  legend(off) ///
		scheme(s2manual) graphregion( color(white)) xtitle("")
graph export "..\output\robusthist2.eps", as(eps) preview(on) replace

count if tstat < 1.64
tab donor  if tstat < 1.96
tab recipient  if tstat < 1.64
hist tstat ,    legend(off) ///
		scheme(s2manual) graphregion( color(white)) xtitle("")
graph export "..\output\robusthisttstat2.eps", as(eps) preview(on) replace

use resultat1, clear
sum estimate, det
tab donor  if estimate <r(p1)
hist estimate ,   addplot(pci 0 0.0858576 150  0.0858576)  legend(off) ///
		scheme(s2manual) graphregion( color(white)) xtitle("")
graph export "..\output\robusthist1.eps", as(eps) preview(on) replace

count if tstat < 1.96
tab donor  if tstat < 1.96
tab recipient  if tstat < 1.96
hist tstat ,    legend(off) ///
		scheme(s2manual) graphregion( color(white)) xtitle("")
graph export "..\output\robusthisttstat1.eps", as(eps) preview(on) replace






